package org.hepeng.workx.spring.cloud.config;

import org.apache.commons.collections.CollectionUtils;
import org.joor.Reflect;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.environment.JGitEnvironmentRepository;
import org.springframework.cloud.config.server.environment.SearchPathCompositeEnvironmentRepository;

import java.util.List;

/**
 * @author he peng
 */
public class JGitRepositoryUtils {

    public static JGitEnvironmentRepository getFirstRepository(SearchPathCompositeEnvironmentRepository repository) {
        List<EnvironmentRepository> environmentRepositories = Reflect.on(repository).get("environmentRepositories");
        if (CollectionUtils.isNotEmpty(environmentRepositories)) {
            return  (JGitEnvironmentRepository) environmentRepositories.get(0);
        }
        return null;
    }

}
